package com.hequ.merchant.banner.activity;

import android.app.Activity;
import android.os.Bundle;

import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.hequ.merchant.banner.ApplicationHelper;
import com.hequ.merchant.banner.R;
import com.hequ.merchant.banner.entity.Banner;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2015/9/16.
 */
public class BannerActivity extends Activity {
    private SliderLayout mDemoSlider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);
        mDemoSlider = (SliderLayout) findViewById(R.id.slider);

//        HashMap<String,String> url_maps = new HashMap<String, String>();
//        url_maps.put("网络地址1", "http://pic.nipic.com/2007-12-16/20071216111124205_2.jpg");
//        url_maps.put("网络地址2", "http://photo.l99.com/bigger/01/1356509659589_hh05w7.jpeg");
//
//
//        HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
//        file_maps.put("Hannibal",R.drawable.hannibal);
//        file_maps.put("Big Bang Theory", R.drawable.bigbang);
//        file_maps.put("House of Cards", R.drawable.house);
//        file_maps.put("Game of Thrones", R.drawable.game_of_thrones);


        List<Banner> banners = ApplicationHelper.getBanners();
        if (banners.size() > 0) {
            HashMap<String,String> bannerMaps = new HashMap<String, String>();
            for (int i = 0; i < banners.size(); i++) {
                bannerMaps.put(banners.get(i).getName(), banners.get(i).getImage());
            }

            for(String name : bannerMaps.keySet()){
                TextSliderView textSliderView = new TextSliderView(this);
                // initialize a SliderLayout
                textSliderView.description(name)
                        .image(bannerMaps.get(name))
                        .setScaleType(BaseSliderView.ScaleType.Fit)
                        .setOnSliderClickListener(bannerClickListener);

                //add your extra information
                textSliderView.bundle(new Bundle());
                textSliderView.getBundle().putString("extra",name);

                mDemoSlider.addSlider(textSliderView);
            }
        }


//        for(String name : url_maps.keySet()){
//            TextSliderView textSliderView = new TextSliderView(this);
//            // initialize a SliderLayout
//            textSliderView.description(name)
//                    .image(url_maps.get(name))
//                    .setScaleType(BaseSliderView.ScaleType.Fit)
//                    .setOnSliderClickListener(bannerClickListener);
//
//            //add your extra information
//            textSliderView.bundle(new Bundle());
//            textSliderView.getBundle().putString("extra",name);
//
//            mDemoSlider.addSlider(textSliderView);
//        }

//        for(String name : file_maps.keySet()){
//            TextSliderView textSliderView = new TextSliderView(this);
//            // initialize a SliderLayout
//            textSliderView.description(name)
//                    .image(file_maps.get(name))
//                    .setScaleType(BaseSliderView.ScaleType.Fit)
//                    .setOnSliderClickListener(bannerClickListener);
//
//            //add your extra information
//            textSliderView.bundle(new Bundle());
//            textSliderView.getBundle().putString("extra",name);
//
//            mDemoSlider.addSlider(textSliderView);
//        }

        mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
        mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        mDemoSlider.setCustomAnimation(new DescriptionAnimation());
        mDemoSlider.setDuration(4000);
    }

    @Override
    protected void onStop() {
        // To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed
        mDemoSlider.stopAutoCycle();
        super.onStop();
    }

    private BaseSliderView.OnSliderClickListener bannerClickListener = new  BaseSliderView.OnSliderClickListener(){
        @Override
        public void onSliderClick(BaseSliderView baseSliderView) {

        }
    };

}
